package com.workingpub.commons.domain;

import javax.persistence.Id;
import javax.persistence.MappedSuperclass;

/**
 * 主键生成策略
 * <li>auto-increment 自增长</li>
 * 
 * @author Kevin(Ping)Tao
 *
 */
@MappedSuperclass
public abstract class AutoIncrementIdentifier implements Identifiable<Long> {

	private static final long serialVersionUID = 1414966911047781675L;

	@Id
	protected Long id;

	@Override
	public Long getId() {
		return id;
	}

	@Override
	public void setId(Long id) {
		this.id = id;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		AutoIncrementIdentifier other = (AutoIncrementIdentifier) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "id : " + id;
	}
}
